const ws = new WebSocket("ws://localhost:8080/ws")

const talkEle = document.getElementById("talk")

ws.onopen = function () {
    console.log("连接成功")
    ws.send("你好，服务器")
}

ws.onmessage = function (message) {
    console.log("收到消息：" + message.data)

    talkEle.innerHTML = message.data
}

ws.onclose = function () {
    console.log("连接关闭")
}